package com.payment.service.impl;

import com.payment.plugin.PaymentPlugin;
import com.payment.service.PluginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @ClassName: PaymentService
 * @Description:
 * @author: fengcheng
 * @date: 2021/03/25
 */
@Service("pluginService")
@Slf4j
public class PluginServiceImpl implements PluginService {
    @Autowired
    private Map<String, PaymentPlugin> paymentPluginMap = new HashMap<>();

    @Override
    public PaymentPlugin getPaymentPlugin(String paymentPluginId) {
        PaymentPlugin paymentPlugin = paymentPluginMap.get(paymentPluginId);
        if (Objects.isNull(paymentPlugin)) {
            log.error("Pay type is unknown, unknown payAppId is : {}", paymentPluginId);
//            throw new Exception("未知支付方式，请联系管理员！");
        }
        return paymentPlugin;
    }
}
